package top.frsf.bullets;

import top.frsf.GamePanel;
import top.frsf.zombies.ZomObject;

import java.awt.*;

/**
 * @BelongsProject: MiniPZ
 * @BelongsPackage: top.frsf.bullets
 * @Author: FRSF
 * @CreateTime: 2022-09-10  16:22
 * @Description: 豌豆射手子弹
 * @Version: 1.0
 */
public class PesBullet extends BulletObject {

    public PesBullet(String img, int x, int y, int width, int height) {
        super(img, x, y, width, height, 10);
    }

    // 子弹移动
    @Override
    public void move() {
        setX(getX() + 5);
    }

    // 子弹销毁
    @Override
    public void destroy() {
        // 子弹出界
        if (getX() > GamePanel.WIDTH) {
            GamePanel.bulStart.delBulList.add(this);
            return;
        }

        // 子弹击中zom
        for (ZomObject zom : GamePanel.zomStart.zomList) {
            if (zom.getRec().contains(getRec())) {
                GamePanel.bulStart.delBulList.add(this);
                zom.downHP(heartHp);
            }
        }
    }

    @Override
    public void paintSelf(Graphics g) {
        super.paintSelf(g);
        move();
        destroy();
    }
}
